from common.operation_excel import OperationExcel
from common.register_data import RegisterData
from page.register_page import RegisterPage
from page.register_page import register_url
from common.operation_excel import data

file_path = './data/test_register.xls'
operation = OperationExcel(file_path)


class RegisterScripts(object):

    def __init__( self, driver ):
        self.register_page = RegisterPage(driver)
        self.register_page.open_url(register_url)
        self.register_data = RegisterData()

    def register_check_question( self ):
        """注册选择密码问题,索引不能为0"""
        self.register_page.home_click_register()
        data_info = self.register_data.write_info_question()
        # 调用验证用户名方法--确认是否重复
        self.register_page.input_username(data_info['username'])
        # 调用邮箱验证方法--确认是否重复
        self.register_page.input_email(data_info['email'])
        self.register_page.input_password(data_info['password'])
        self.register_page.input_repassword(data_info['repassword'])
        self.register_page.input_tel(data_info['tel'])
        self.register_page.check_password_question(data_info['question'])
        self.register_page.answer(data_info['answer'])
        self.register_page.click_register()
        self.register_data.write(data_info)

    def register_no_question( self ):
        """注册选择密码问题,索引不能为0"""
        self.register_page.home_click_register()
        data_info = self.register_data.write_info()
        # 调用验证用户名方法--确认是否重复
        self.register_page.input_username(data_info['username'])
        # 调用邮箱验证方法--确认是否重复
        self.register_page.input_email(data_info['email'])
        self.register_page.input_password(data_info['password'])
        self.register_page.input_repassword(data_info['repassword'])
        self.register_page.input_tel(data_info['tel'])
        question = 0
        self.register_page.check_password_question(question)
        answer = ''
        self.register_page.answer(answer)
        self.register_page.click_register()
        data.append(data_info)
        self.register_data.write(data_info)
    def is_register_scuess( self, username ):
        login_success_loc = ("class name", "f4_b")
        res = self.register_page.is_text_in_element(login_success_loc, username)
        return res

    def jump_home_page( self ):
        """跳转到首页"""
        self.register_page.home_click_register()
        self.register_page.click_home_page()

    def jump_agreement( self ):
        """跳转到协议内容"""
        self.register_page.home_click_register()
        self.register_page.click_agreement()

    def jump_login( self ):
        """跳转到登录页面"""
        self.register_page.home_click_register()
        self.register_page.click_login()

    def jump_find_password( self ):
        self.register_page.home_click_register()
        self.register_page.click_find_password()
